package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractVersionEntity;
import com.moyuer.bsf.domain.model.Organ;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

/**
 * 基础实体
 *
 * @author: 袁首京<yuanshoujing@gmail.com>
 * 16/4/13
 */
@MappedSuperclass
public abstract class BaseEntity extends AbstractVersionEntity {

    @JSONField(serialize = false)
    @ManyToOne
    @NotFound(action = NotFoundAction.IGNORE)
    private Organ organ; // 所属机构

    private String remark; // 备注

    @Transient
    private String organId;
    @Transient
    private String organName;

    public Organ getOrgan() {
        return organ;
    }

    public void setOrgan(Organ organ) {
        this.organ = organ;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getOrganId() {
        if (organId != null) {
            return organId;
        }

        if (organ != null) {
            organId = organ.getId();
        }

        return organId;
    }

    public void setOrganId(String organId) {
        this.organId = organId;
    }

    public String getOrganName() {
        if (organName != null) {
            return organName;
        }

        if (organ != null) {
            organName = organ.getName();
        }

        return organName;
    }

    public void setOrganName(String organName) {
        this.organName = organName;
    }
}
